package com.redstars.generate.controller;

import com.redstars.generate.page.PageResult;
import com.redstars.generate.result.Result;
import com.redstars.generate.vo.SysBaseClassVo;
import lombok.AllArgsConstructor;
import com.redstars.generate.service.SysBaseClassService;
import com.redstars.generate.query.SysBaseClassQuery;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
* 基类管理
*
* @author zhouhx 
* @since 1.0.0 2022-10-05
*/
@RestController
@RequestMapping("gen/baseclass")
@AllArgsConstructor
public class SysBaseClassController {
    private final SysBaseClassService sysBaseClassService;

    /* *
     *
     * @author zhuohx
     * @description 分页
     * @parms  [query]
     * @return com.redstars.generate.result.Result<com.redstars.generate.page.PageResult<com.redstars.generate.vo.SysBaseClassVo>>
     * @throws
     * @date 2022/10/5 15:47
     */
    @GetMapping("page")
    public Result<PageResult<SysBaseClassVo>> page(@Valid SysBaseClassQuery query){
        PageResult<SysBaseClassVo> page = sysBaseClassService.page(query);

        return Result.ok(page);
    }

    /* *
     *
     * @author zhuohx
     * @description 详情
     * @parms  [query]
     * @return com.redstars.generate.result.Result<com.redstars.generate.vo.SysBaseClassVo>
     * @throws
     * @date 2022/10/5 15:47
     */
    @GetMapping("{id}")
    public Result<SysBaseClassVo> detail(@PathVariable("id") Long id){
        SysBaseClassVo detail = sysBaseClassService.detail(id);

        return Result.ok(detail);
    }

    /* *
     *
     * @author zhuohx
     * @description 保存
     * @parms  [vo]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:47
     */
    @PostMapping
    public Result<String> save(@RequestBody SysBaseClassVo vo){
        sysBaseClassService.save(vo);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 修改
     * @parms  [vo]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:48
     */
    @PutMapping
    public Result<String> update(@RequestBody @Valid SysBaseClassVo vo){
        sysBaseClassService.update(vo);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 删除
     * @parms  [idList]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:48
     */
    @DeleteMapping
    public Result<String> delete(@RequestBody List<Long> idList){
        sysBaseClassService.delete(idList);

        return Result.ok();
    }

    @GetMapping("list")
    public Result<List<SysBaseClassVo>> list(SysBaseClassQuery query) {
        List<SysBaseClassVo> list = sysBaseClassService.list(query);

        return Result.ok(list);
    }
}